此篇笔记记录如何支持多域名免登陆 ssh git 配置,这里备忘一下。
ssh 公钥生成
生成, 默认文件名为id_rsa
1
| ssh-keygen -t rsa -C "your_email@example.com"
|
多个key的情况, second为文件名称
1
| ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/second
|
服务端配置
将生成的xxx.pub的内容拷贝到对应的网站中
ssh config 配置. ~/.ssh/config
- Host >域名
- User >用户名
- IdentityFile >ssh key的路径
- IdentitiesOnly >只使用这里设置的key, 防止使用默认的
- ServerAliveInterval >连接保持
- ControlMaster auto >不用重新登录
- ControlPath ~/.ssh/master-%r@%h:%p
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Host github.com User git IdentityFile ~/.ssh/id_gmail IdentitiesOnly yes Host bitbucket.org User git IdentityFile ~/.ssh/id_gmail IdentitiesOnly yes Host git.coding.net User git IdentityFile ~/.ssh/id_gmail IdentitiesOnly yes Host git.oschina.net User git IdentityFile ~/.ssh/id_gmail IdentitiesOnly yes Host *.alibaba-inc.com User git IdentityFile ~/.ssh/id_rsa Host * ServerAliveInterval 60 ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p
|
保存
1
| ssh-add -K ~/.ssh/id_ssh
|
连接测试
git 名称设置
1 2
| git config --global user.name "User name" git config --global user.email user@example.com
|
如果不设置全局的, 在项目目录下执行, 去掉–global即可